package com.atguigu.juc.day02;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author atguigu-mqx
 */
class A extends Thread{
    @Override
    public void run() {
        System.out.println("Thread....");
        super.run();
    }
}
class B implements Runnable{

    @Override
    public void run() {
        System.out.println("Runnable....");
    }
}

class C implements Callable{

    @Override
    public String call() throws Exception {
        System.out.println("Callable....");
        return "hello";
    }
}

public class Test {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        //  创建线程并运行：
        //        new A().start();
        //        new Thread(new B()).start();
        //  ----------------------------------------------
        FutureTask futureTask = new FutureTask<>(new C());

        FutureTask futureTask1 = new FutureTask<>(new C());
        //  一个futureTask 被执行了两次！
        new Thread(futureTask,"AA").start();
        new Thread(futureTask,"CC").start();

        new Thread(futureTask1,"BB").start();

        //  判断当前任务是否执行完成！
        //  boolean result = futureTask.isDone();
        //  result = true: 表示执行完成  false ： 表示未完成 if -- while result = false
        //  while (result){
//            System.out.println(futureTask.get());
            //  System.out.println("等待.....");
        //  }
        //        while (!futureTask.isDone()){
        //            System.out.println("等待......");
        //        }
        System.out.println(futureTask.get());
        //  System.out.println(futureTask.get());
        System.out.println(futureTask1.get());
        //  需要调用方法了.


    }
}
